package com.ymttest.business.service;

import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.activitymgt.parameter.CatalogAgentBean;
import com.shop2cn.iapi.activitymgt.parameter.ProductAgentBean;
import com.shop2cn.iapi.activitymgt.parameter.endactivityBean;
import com.shop2cn.iapi.activitymgt.service.AddactivityCall;
import com.shop2cn.iapi.activitymgt.service.endactivityCall;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.GetCurrencyConfigBean;
import com.shop2cn.iapi.shenqisettlement.parameter.resp.GetCurrencyConfigResp;
import com.shop2cn.iapi.shenqisettlement.service.GetCurrencyConfigCall;
import com.shop2cn.iapi.agentproducts.parameter.*;
import com.shop2cn.iapi.agentproducts.service.ActivityListCall;
import com.shop2cn.iapi.agentproducts.service.ImportProductByActivityIdCall;
import com.shop2cn.iapi.agentproducts.service.UpdateStockCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.iapi.productsynces.parameter.ESsearchBean;
import com.ymatou.iapi.productsynces.parameter.es.EsGodProduct;
import com.ymatou.iapi.productsynces.parameter.es.EsProduct;
import com.ymatou.iapi.productsynces.service.ESGodsearchCall;
import com.ymt.core.tool.Logger;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.*;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductCategoryWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.godfreight.freight_templateWapper;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import java.io.IOException;
import java.math.BigDecimal;
import java.security.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.joda.time.DateTime;
import org.json.JSONException;

//神器新库验证
public class AgentProductCallServiceV2 {

	private static IntergratedProductMapper ipm = SqlMapperFactory.getIntergratedProductMapper();
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	private static YmtProductCategoryWapper ymtProductCategoryWapper = new YmtProductCategoryWapper();
	private static mch_infoWapper infoWapper = new mch_infoWapper();
	private static mch_relationWapper mchRelationWapper = new mch_relationWapper();
	private static agent_typeWapper agentTypeWapper = new agent_typeWapper();
	
	
	/**
	 * 根据商户id，查询活动列表
	 * @param agentUserId
	 * @return 
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonObject ActivityList(int agentUserId) throws ClientProtocolException, IOException {
		ActivityListBean activitylistBean = new ActivityListBean();
		ActivityListCall activitylistCall = new ActivityListCall();
		activitylistBean.setUserId(agentUserId);
		
		activitylistCall.setData(activitylistBean);
		activitylistCall.callService();			
		Logger.verifyEquals("200", activitylistCall.getString("code"), "验证code");
		return activitylistCall.getJsonObject();
	}
	/**
	 * 通过活动id将活动添加到我的店
	 * @param agentUserId
	 * @param activityId
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static void ImportProductByActivityId(int agentUserId,int activityId) throws ClientProtocolException, IOException, InterruptedException {

		ImportProductByActivityIdBean importproductbyactivityidBean = new ImportProductByActivityIdBean();
		ImportProductByActivityIdCall importproductbyactivityidCall = new ImportProductByActivityIdCall();
		importproductbyactivityidBean.setUserId(agentUserId);
		importproductbyactivityidBean.setActivityId(activityId);
		importproductbyactivityidCall.setData(importproductbyactivityidBean);
		importproductbyactivityidCall.callService();			
		Logger.verifyEquals("200", importproductbyactivityidCall.getString("code"), "验证code");
		Thread.sleep(3000);
	}
	
	
	/**
	 * 查询神器es信息
	 * @param productId
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * @throws JSONException 
	 * @throws JsonSyntaxException 
	 */
	public static EsGodProduct getAgentProductEs(String productId) throws ClientProtocolException, IOException, JsonSyntaxException, JSONException {
		//查询es
		ESGodsearchCall ESGodsearchCall=new ESGodsearchCall();
		
		ESsearchBean ESsearchBean=new ESsearchBean();
		ESsearchBean.setProductId("pid:"+productId);
		ESGodsearchCall.setData(ESsearchBean);
		ESGodsearchCall.callService();
		
		EsGodProduct EsProduct=ESGodsearchCall.getEsProduct();
		return EsProduct;
	}
	/**
	 * 根据国家获取币种详情
	 * 
	 * @param currency
	 * @return
	 * @throws IOException
	 */
	public static GetCurrencyConfigResp getCurrencyConfigResp(String currency) throws IOException {
		GetCurrencyConfigBean getcurrencyconfigBean = new GetCurrencyConfigBean();
		GetCurrencyConfigCall getcurrencyconfigCall = new GetCurrencyConfigCall();
		getcurrencyconfigBean.setCurrency(currency);
		getcurrencyconfigCall.setData(getcurrencyconfigBean);
		getcurrencyconfigCall.callService();
		return getcurrencyconfigCall.getCurrencyConfigResp();
	}

	public static void checkAddAgentProduct(String productId, AddAgentProductBean agentProductBean, boolean isCsId)
			throws Exception {
		Map<String, Object> pmap = ipm.selectProductByProdId(productId);
		// check product
		Logger.comment("验证product：" + productId);
		int sellerId = 0;
		if (isCsId) {
			sellerId = Integer.parseInt(new DefGodMchWapper().selectCsInfoByCsId(agentProductBean.getUserId()).get(0)
					.get("mchId").toString());
		} else {
			sellerId = agentProductBean.getUserId();
		}
		Logger.verifyEquals(sellerId, Integer.parseInt(pmap.get("iUserId").toString()), "验证SellerId");
		Logger.verifyEquals(agentProductBean.getTitle(), pmap.get("sProduct").toString(), "验证productName");
		Logger.verifyEquals(agentProductBean.getCatalogStatus(),
				Integer.parseInt(pmap.get("iCatalogStatus").toString()), "验证商品物流类型");
		if (agentProductBean.getCatalogStatus() == 999) {
			Logger.verifyEquals(0, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (agentProductBean.getCatalogStatus() == 100 && agentProductBean.getCardInfo() == 1) {
			Logger.verifyEquals(1, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (agentProductBean.getCatalogStatus() == 0) {
			Logger.verifyEquals(0, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (agentProductBean.getCatalogStatus() == 4) {
			Logger.verifyNotEquals(2, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else {
			Logger.verifyEquals(2, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		}
		Logger.verifyEquals(agentProductBean.getCategoryId() == null ? 0 : agentProductBean.getCategoryId(),
				Integer.parseInt(pmap.get("iCategoryId").toString()), "验证二级类目编号");
		Logger.verifyEquals(agentProductBean.getThirdCategoryId() == null ? 0 : agentProductBean.getThirdCategoryId(),
				Integer.parseInt(pmap.get("iThirdCategoryId").toString()), "验证商品三级类目编号");
		Logger.verifyEquals(agentProductBean.getBrandId(), Integer.parseInt(pmap.get("iBrandId").toString()), "验证品牌编号");
		Logger.verifyEquals(agentProductBean.getRemark(), pmap.get("Remark").toString(), "验证商品描述");
		Logger.verifyEquals(agentProductBean.getPics().get(0), pmap.get("sPicUrl").toString(), "验证商品主图（首图）");
//		Logger.verifyEquals(0, Integer.parseInt(pmap.get("iAction").toString()), "验证action");
		Logger.verifyEquals(3, Integer.parseInt(pmap.get("ProductType").toString()), "验证商品类型");

		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dAddTime"), 120, "验证商品发布时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dLastUpdate"), 120, "验证商品最后更新时间");

		GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(agentProductBean.getCurrency());
		Logger.verifyEquals(agentProductBean.getCurrency(), currencyConfigResp.getCurrency(), "验证currency");

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId, sellerId);

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		agentProductBean.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, sellerId).stream()
				.map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(agentProductBean.getDescription()), "验证Description");

		// check pic
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < agentProductBean.getPics().size(); i++) {
			Logger.comment("验证pictures");
			Logger.verifyEquals(agentProductBean.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		// check catalog
		List<YmtCatalogsI> ymtCatalogsIList = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
		agentProductBean.getCatalogList().forEach(p -> {
			for (YmtCatalogsI ymtCatalogsI : ymtCatalogsIList) {
				// check Ymt_CatalogSetAttributes
				if (ymtCatalogsI.getsSKU().equals(p.getSku())) {
					Logger.comment("验证规格");
					Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(), "验证直销价");
					System.out.println(p.toString());
					System.out.println(ymtCatalogsI.toString());
					Logger.verifyEquals(p.getStock()+ymtCatalogsI.getVirtualStock(), ymtCatalogsI.getiNum(), "验证总库存");
					Logger.verifyEquals(p.getVirtualStock()==null?0:p.getVirtualStock(), ymtCatalogsI.getVirtualStock(), "验证虚拟库存");
					
					if (ymtCatalogsI.getiNum() == 0 || ymtCatalogsI.getfQuotePrice().doubleValue() == 0.0) {
						Logger.verifyEquals(-2, ymtCatalogsI.getiAction(), "验证action");
					} else {
						Logger.verifyEquals(0, ymtCatalogsI.getiAction(), "验证action");
					}
					Logger.verifyEquals(p.getSku(), ymtCatalogsI.getsSKU(), "验证sku");
					Logger.verifyEquals(p.getPic(), ymtCatalogsI.getsPicUrl(), "验证pic");
					Logger.verifyEquals(p.getWeight(), ymtCatalogsI.getWeight().doubleValue(), "验证Weight");
					AssertService.assertTime(YMTDateUtil.getDate(), (Date) ymtCatalogsI.getdAddTime(), 120,
							"验证商品规格的发布时间");
				}
				// 验证规格属性
				List<Map<String, Object>> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId());
				map.forEach(x -> {
					p.getPropertyList().forEach(o -> {
						if (o.getValue().equals(x.get("sCategoryAttribute").toString())) {
							Logger.verifyEquals(o.getName(), x.get("sProductProperty").toString(), "验证name");
							Logger.verifyEquals(o.getPic(), x.get("sPicUrl").toString(), "验证pic");
							Logger.verifyEquals(o.getSubType(), x.get("SubType").toString(), "验证SubType");
						}
					});
				});

				// check ymt_AgentPrice
				if (agentProductBean.getSetAgentPrice()) {
					p.getAgentPriceList().forEach(x -> {
						List<AgentPricePo> agentPricePos = ymtProductsIWapper
								.selectAgentPriceByCatalogId(ymtCatalogsI.getsCatalogId(), x.getAgentTypeId());
						agentPricePos.forEach(c -> {
							if (x.getAgentPrice() == c.getAgentPrice()) {
								Logger.comment("验证代理价格");
								Logger.verifyEquals(x.getAgentTypeId(), c.getAgentTypeId(), "验证代理价格");
								Logger.verifyEquals(productId, c.getProductId(), "验证productId");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getCreateTime(), 120,
										"验证创建时间");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getUpdateTime(), 120,
										"验证更新时间");
							}
						});
					});
				}
			}
		});
		// check AgentProducts
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		Logger.comment("验证AgentProducts");
		Logger.verifyEquals(sellerId, agentProductPo.getUserId(), "验证UserId");
		Logger.verifyEquals(0, agentProductPo.getAgentType(), "验证代理类型");
		Logger.verifyEquals(agentProductBean.isInvisible(), agentProductPo.isInvisible(), "验证Invisible");
		Logger.verifyEquals(agentProductBean.getSetAgentPrice(), agentProductPo.isSetAgentPrice(), "验证是否允许下级代理");
		if (agentProductBean.getSaleType() == 2) {
			Logger.verifyEquals(2, agentProductPo.getStatus(), "验证商品是下架状态");
		} else {
			Logger.verifyEquals(1, agentProductPo.getStatus(), "验证商品是上架状态");
		}
//		Logger.verifyEquals(0, agentProductPo.getAction(), "验证商品action");
		Logger.verifyEquals(0, agentProductPo.getParentUserId(), "验证商品parentUserId");
		Logger.verifyEquals(null, agentProductPo.getParentProductId(), "验证商品parentProductId");
		Logger.verifyEquals(sellerId, agentProductPo.getRootUserId(), "验证商品parentProductId");
		Logger.verifyEquals(productId, agentProductPo.getRootProductId(), "验证商品rootProductId");
		mch_info minfo = infoWapper.selectby(MapUtil.hashMap("mchId", sellerId)).get(0);
		Logger.verifyEquals(true, agentProductPo.getAgentChain().contains(minfo.getSeqId().toString()), "验证AgentChain");
		Logger.verifyEquals(0, agentProductPo.getAgentType(), "验证agentType");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) agentProductPo.getCreateTime(), 120, "验证创建时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) agentProductPo.getUpdateTime(), 120, "验证更新时间");

		// check Ymt_AgentWxCodePic
		Thread.sleep(2000);
		Map map = ymtProductsIWapper.selectAgentWxCodePicByProductId(productId).get(0);
		Logger.verifyEquals(agentProductPo.getUserId(), Integer.parseInt(map.get("UserId").toString()), "验证UserId");
//		Logger.verifyEquals(1, Integer.parseInt(map.get("Action").toString()), "验证Action");

		// check Ymt_ProductDeliveryTemplate
		if (agentProductBean.getFreightTemplateId() != null && agentProductBean.getFreightTemplateId() != 0) {
			Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(productId).get(0);
			Logger.debug("deliMap:" + deliMap);
			Logger.verifyEquals(agentProductBean.getUserId(), Integer.parseInt(deliMap.get("SellerId").toString()),
					"验证sellerId");
			Logger.verifyEquals(agentProductBean.getFreightTemplateId(),
					Integer.parseInt(deliMap.get("TemplateId").toString()), "验证TemplateId");
			Logger.verifyEquals(agentProductBean.getCatalogStatus(),
					Integer.parseInt(deliMap.get("CatalogStatus").toString()), "验证CatalogStatus");
			Logger.verifyEquals(1, Integer.parseInt(deliMap.get("Status").toString()), "验证Status");
			Logger.verifyEquals(productId, deliMap.get("ProductId").toString(), "验证ProductId");
		}
	}
	
	
	public static void checkAddProduct(String productId, AddProductBean ProductBean, boolean isCsId)
			throws Exception {
		HashMap<String, Object> pmap = (HashMap<String, Object>) ipm.selectProductByProdId(productId);
		System.out.println(pmap);
		// check product
		Logger.comment("验证product：" + productId);
		int sellerId = 0;
		if (isCsId) {
			sellerId = Integer.parseInt(new DefGodMchWapper().selectCsInfoByCsId(ProductBean.getUserId()).get(0)
					.get("mchId").toString());
		} else {
			sellerId = ProductBean.getUserId();
		}
		
		Logger.verifyEquals(sellerId, Integer.parseInt(pmap.get("iUserId").toString()), "验证SellerId");
		Logger.verifyEquals(ProductBean.getTitle(), pmap.get("sProduct").toString(), "验证productName");
		Logger.verifyEquals(ProductBean.getDepotId()==null?0:ProductBean.getDepotId(), Integer.parseInt(pmap.get("iBondedArea").toString()), "验证iBondedArea");
		Logger.verifyEquals(ProductBean.getCatalogStatus(),
				Integer.parseInt(pmap.get("iCatalogStatus").toString()), "验证商品物流类型");
		if (ProductBean.getCatalogStatus() == 999) {
			Logger.verifyEquals(0, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (ProductBean.getCatalogStatus() == 100 && ProductBean.getCardInfo() == 1) {
			Logger.verifyEquals(1, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (ProductBean.getCatalogStatus() == 0) {
			Logger.verifyEquals(0, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else if (ProductBean.getCatalogStatus() == 4) {
			Logger.verifyNotEquals(2, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		} else {
			Logger.verifyEquals(2, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");
		}
		
		Logger.verifyEquals(ProductBean.getCategoryId() == 0 ? 0 : ProductBean.getCategoryId(),
				Integer.parseInt(pmap.get("iCategoryId").toString()), "验证二级类目编号");
		Logger.verifyEquals(ProductBean.getThirdCategoryId() == 0 ? 0 : ProductBean.getThirdCategoryId(),
				Integer.parseInt(pmap.get("iThirdCategoryId").toString()), "验证商品三级类目编号");
		Logger.verifyEquals(ProductBean.getBrandId(), Integer.parseInt(pmap.get("iBrandId").toString()), "验证品牌编号");
//		Logger.verifyEquals(ProductBean.getRemark(), pmap.get("Remark").toString(), "验证商品描述");
		Logger.verifyEquals(ProductBean.getPics().get(0), pmap.get("sPicUrl").toString(), "验证商品主图（首图）");
//		Logger.verifyEquals(0, Integer.parseInt(pmap.get("iAction").toString()), "验证action");
		Logger.verifyEquals(3, Integer.parseInt(pmap.get("ProductType").toString()), "验证商品类型");

		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dAddTime"), 120, "验证商品发布时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dLastUpdate"), 120, "验证商品最后更新时间");

		GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(ProductBean.getCurrency());
		Logger.verifyEquals(ProductBean.getCurrency(), currencyConfigResp.getCurrency(), "验证currency");

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId, sellerId);

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		ProductBean.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, sellerId).stream()
				.map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(ProductBean.getDescription()), "验证Description");

		// check pic
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < ProductBean.getPics().size(); i++) {
			Logger.comment("验证pictures");
			Logger.verifyEquals(ProductBean.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		// check catalog
		List<YmtCatalogsI> ymtCatalogsIList = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
		ProductBean.getCatalogList().forEach(p -> {
			for (YmtCatalogsI ymtCatalogsI : ymtCatalogsIList) {
				// check Ymt_CatalogSetAttributes
				if (ymtCatalogsI.getsSKU().equals(p.getSku())) {
					Logger.comment("验证规格");
					Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(), "验证直销价");
					System.out.println(p.toString());
					System.out.println(ymtCatalogsI.toString());
					Logger.verifyEquals(p.getStock(), ymtCatalogsI.getiNum(), "验证总库存");
					Logger.verifyEquals(p.getVirtualStock()==null?0:p.getVirtualStock(), ymtCatalogsI.getVirtualStock(), "验证虚拟库存");
					
					if (ymtCatalogsI.getiNum() == 0 || ymtCatalogsI.getfQuotePrice().doubleValue() == 0.0) {
						Logger.verifyEquals(-2, ymtCatalogsI.getiAction(), "验证action");
					} else {
						Logger.verifyEquals(0, ymtCatalogsI.getiAction(), "验证action");
					}
					Logger.verifyEquals(p.getSku(), ymtCatalogsI.getsSKU(), "验证sku");
					Logger.verifyEquals(p.getPic(), ymtCatalogsI.getsPicUrl(), "验证pic");
					Logger.verifyEquals(p.getWeight(), ymtCatalogsI.getWeight().doubleValue(), "验证Weight");
					AssertService.assertTime(YMTDateUtil.getDate(), (Date) ymtCatalogsI.getdAddTime(), 120,
							"验证商品规格的发布时间");
				}
				
				// 验证规格属性
				List<Map<String, Object>> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId());
				map.forEach(x -> {
					p.getPropertyList().forEach(o -> {
						if (o.getValue().equals(x.get("sCategoryAttribute").toString())) {
							Logger.verifyEquals(o.getName(), x.get("sProductProperty").toString(), "验证name");
							Logger.verifyEquals(o.getPic(), x.get("sPicUrl").toString(), "验证pic");
							Logger.verifyEquals(o.getSubType(), x.get("SubType").toString(), "验证SubType");
						}
					});
				});

				// check ymt_AgentPrice
				if (ProductBean.getSetAgentPrice()) {
					p.getAgentPriceList().forEach(x -> {
						List<AgentPricePo> agentPricePos = ymtProductsIWapper
								.selectAgentPriceByCatalogId(ymtCatalogsI.getsCatalogId(), x.getAgentTypeId());
						agentPricePos.forEach(c -> {
							if (x.getAgentPrice() == c.getAgentPrice()) {
								Logger.comment("验证代理价格");
								Logger.verifyEquals(x.getAgentTypeId(), c.getAgentTypeId(), "验证代理价格");
								Logger.verifyEquals(productId, c.getProductId(), "验证productId");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getCreateTime(), 120,
										"验证创建时间");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getUpdateTime(), 120,
										"验证更新时间");
							}
						});
					});
				}
			}
		});
		// check Products
		AgentProductPo ProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		Logger.comment("验证Products");
		Logger.verifyEquals(sellerId, ProductPo.getUserId(), "验证UserId");
		Logger.verifyEquals(0, ProductPo.getAgentType(), "验证代理类型");
		Logger.verifyEquals(ProductBean.getSetAgentPrice(), ProductPo.isSetAgentPrice(), "验证是否允许下级代理");
		if (ProductBean.getSaleType() == 2) {
			Logger.verifyEquals(2, ProductPo.getStatus(), "验证商品是下架状态");
		} else {
			Logger.verifyEquals(1, ProductPo.getStatus(), "验证商品是上架状态");
		}
//		Logger.verifyEquals(0, ProductPo.getAction(), "验证商品action");
		Logger.verifyEquals(0, ProductPo.getParentUserId(), "验证商品parentUserId");
		Logger.verifyEquals(null, ProductPo.getParentProductId(), "验证商品parentProductId");
		Logger.verifyEquals(sellerId, ProductPo.getRootUserId(), "验证商品parentProductId");
		Logger.verifyEquals(productId, ProductPo.getRootProductId(), "验证商品rootProductId");
		mch_info minfo = infoWapper.selectby(MapUtil.hashMap("mchId", sellerId)).get(0);
		Logger.verifyEquals(true, ProductPo.getAgentChain().contains(minfo.getSeqId().toString()), "验证AgentChain");
		Logger.verifyEquals(0, ProductPo.getAgentType(), "验证agentType");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) ProductPo.getCreateTime(), 120, "验证创建时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) ProductPo.getUpdateTime(), 120, "验证更新时间");

		// check Ymt_AgentWxCodePic
		Thread.sleep(2000);
		Map map = ymtProductsIWapper.selectAgentWxCodePicByProductId(productId).get(0);
		Logger.verifyEquals(ProductPo.getUserId(), Integer.parseInt(map.get("UserId").toString()), "验证UserId");
//		Logger.verifyEquals(1, Integer.parseInt(map.get("Action").toString()), "验证Action");

		// check Ymt_ProductDeliveryTemplate
		if (ProductBean.getFreightTemplateName() != null && ProductBean.getFreightTemplateName() != null) {
			Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(productId).get(0);
			Logger.debug("deliMap:" + deliMap);
			Logger.verifyEquals(ProductBean.getUserId(), Integer.parseInt(deliMap.get("SellerId").toString()),
					"验证sellerId");
			Logger.verifyEquals(ProductBean.getFreightTemplateName(),
					Integer.parseInt(deliMap.get("TemplateName").toString()), "验证TemplateId");
			Logger.verifyEquals(ProductBean.getCatalogStatus(),
					Integer.parseInt(deliMap.get("CatalogStatus").toString()), "验证CatalogStatus");
			Logger.verifyEquals(1, Integer.parseInt(deliMap.get("Status").toString()), "验证Status");
			Logger.verifyEquals(productId, deliMap.get("ProductId").toString(), "验证ProductId");
		}
	}

	public static void checkModifyAgentProduct(ModifyAgentProductBean modifyproductBean) throws Exception {
		String productId = modifyproductBean.getProductId();
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId).get(0);
		YmtProductsI rootYmtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductPo.getRootProductId())
				.get(0);
		Logger.verifyEquals(modifyproductBean.getUserId(), ymtProductsI.getiUserId(), "验证userID");

		GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(modifyproductBean.getCurrency());

		Logger.verifyEquals(modifyproductBean.getCurrency(), currencyConfigResp.getCurrency(), "验证currency");
		Logger.verifyEquals(modifyproductBean.getTitle(), ymtProductsI.getsProduct(), "验证title");
		Logger.verifyEquals(modifyproductBean.getCatalogStatus(), rootYmtProductsI.getiCatalogStatus(),
				"验证catalogStatus");
		Logger.verifyEquals(modifyproductBean.getCardInfo(), rootYmtProductsI.getCardInfo(), "验证cardInfo");
		Logger.verifyEquals(modifyproductBean.getBrandId(), rootYmtProductsI.getiBrandId(), "验证brandId");
		Logger.verifyEquals(modifyproductBean.getRemark(), rootYmtProductsI.getRemark(), "验证remark");
		List<CategoryDtoV2> categoryDtoV2s = ymtProductsIWapper
				.selectCategoryByThirdCategoryId(rootYmtProductsI.getiThirdCategoryId());
		if (categoryDtoV2s.size() != 0) {
			Logger.verifyEquals(modifyproductBean.getThirdCategoryId(), categoryDtoV2s.get(0).getThirdCategoryId(),
					"验证thirdCategoryId");
			Logger.verifyEquals(modifyproductBean.getCategoryId(), categoryDtoV2s.get(0).getSecondCategoryId(),
					"验证categoryId");
		}
		if (modifyproductBean.getSaleType() == 2) {
			Logger.verifyEquals(2, agentProductPo.getStatus(), "验证商品是下架状态");
		} else {
			Logger.verifyEquals(1, agentProductPo.getStatus(), "验证商品是上架状态");
		}
		Logger.verifyEquals(modifyproductBean.getSetAgentPrice(), agentProductPo.isSetAgentPrice(), "验证setAgentPrice");
		Logger.verifyEquals(modifyproductBean.isInvisible(), agentProductPo.isInvisible(), "验证setAgentPrice");
		// check pic
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < modifyproductBean.getPics().size(); i++) {
			Logger.comment("验证pictures");
			Logger.verifyEquals(modifyproductBean.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,
				modifyproductBean.getUserId());

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		modifyproductBean.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, modifyproductBean.getUserId()).stream()
				.map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(modifyproductBean.getDescription()), "验证Description");

		// check Ymt_ProductDeliveryTemplate
		if (modifyproductBean.getFreightTemplateId() != 0) {
			Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(productId).get(0);
			if (Integer.parseInt(deliMap.get("Status").toString()) > -1) {
				Logger.verifyEquals(modifyproductBean.getUserId(), Integer.parseInt(deliMap.get("SellerId").toString()),
						"验证sellerId");
				Logger.verifyEquals(modifyproductBean.getFreightTemplateId(),
						Integer.parseInt(deliMap.get("TemplateId").toString()), "验证TemplateId");
				Logger.verifyEquals(modifyproductBean.getCatalogStatus(),
						Integer.parseInt(deliMap.get("CatalogStatus").toString()), "验证CatalogStatus");
				Logger.verifyEquals(1, Integer.parseInt(deliMap.get("Status").toString()), "验证Status");
				Logger.verifyEquals(productId, deliMap.get("ProductId").toString(), "验证ProductId");
			}
		}

		modifyproductBean.getCatalogList().forEach(p -> {
			try {
				if (p.getCatalogId() != null) {
					YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(p.getCatalogId());
					YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper
							.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
					Logger.verifyEquals(p.getStock(), rootYmtCatalogsI.getiNum(), "验证stock");
					Logger.verifyEquals(p.getSku(), ymtCatalogsI.getsSKU(), "验证sku");
					Logger.verifyEquals(p.getPic(), ymtCatalogsI.getsPicUrl(), "验证pic");
					Logger.verifyEquals(p.getWeight(), ymtCatalogsI.getWeight().doubleValue(), "验证Weight");
					Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().setScale(1).doubleValue(),
							"验证directPrice");

					List<Map<String, Object>> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId());
					map.forEach(x -> {
						p.getPropertyList().forEach(o -> {
							if (o.getValue().equals(x.get("sCategoryAttribute").toString())) {
								Logger.verifyEquals(o.getName(), x.get("sProductProperty").toString(), "验证name");
								Logger.verifyEquals(o.getPic(), x.get("sPicUrl").toString(), "验证pic");
								Logger.verifyEquals(o.getSubType(), x.get("SubType").toString(), "验证SubType");
							}
						});
					});

					if (p.getAgentPriceList() != null && modifyproductBean.getSetAgentPrice()) {
						p.getAgentPriceList().forEach(x -> {
							AgentPricePo agentPricePo = ymtProductsIWapper
									.selectAgentPriceByCatalogId(p.getCatalogId(), x.getAgentTypeId()).get(0);
							Logger.verifyEquals(x.getAgentPrice(), agentPricePo.getAgentPrice(), "验证agentPrice");
						});
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
	}

	public static void checkModifyAgentProductNotsku(ModifyAgentProductBean modifyproductBean) throws Exception {
		String productId = modifyproductBean.getProductId();
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId).get(0);
		YmtProductsI rootYmtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductPo.getRootProductId())
				.get(0);
		Logger.verifyEquals(modifyproductBean.getUserId(), ymtProductsI.getiUserId(), "验证userID");

		GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(modifyproductBean.getCurrency());

		Logger.verifyEquals(modifyproductBean.getCurrency(), currencyConfigResp.getCurrency(), "验证currency");
		Logger.verifyEquals(modifyproductBean.getTitle(), ymtProductsI.getsProduct(), "验证title");
		Logger.verifyEquals(modifyproductBean.getCatalogStatus(), rootYmtProductsI.getiCatalogStatus(),
				"验证catalogStatus");
		Logger.verifyEquals(modifyproductBean.getCardInfo(), rootYmtProductsI.getCardInfo(), "验证cardInfo");
		Logger.verifyEquals(modifyproductBean.getBrandId(), rootYmtProductsI.getiBrandId(), "验证brandId");
		Logger.verifyEquals(modifyproductBean.getRemark(), rootYmtProductsI.getRemark(), "验证remark");
		List<CategoryDtoV2> categoryDtoV2s = ymtProductsIWapper
				.selectCategoryByThirdCategoryId(rootYmtProductsI.getiThirdCategoryId());
		if (categoryDtoV2s.size() != 0) {
			Logger.verifyEquals(modifyproductBean.getThirdCategoryId(), categoryDtoV2s.get(0).getThirdCategoryId(),
					"验证thirdCategoryId");
			Logger.verifyEquals(modifyproductBean.getCategoryId(), categoryDtoV2s.get(0).getSecondCategoryId(),
					"验证categoryId");
		}
		if (modifyproductBean.getSaleType() == 2) {
			Logger.verifyEquals(2, agentProductPo.getStatus(), "验证商品是下架状态");
		} else {
			Logger.verifyEquals(1, agentProductPo.getStatus(), "验证商品是上架状态");
		}
		Logger.verifyEquals(modifyproductBean.getSetAgentPrice(), agentProductPo.isSetAgentPrice(), "验证setAgentPrice");
		Logger.verifyEquals(modifyproductBean.isInvisible(), agentProductPo.isInvisible(), "验证setAgentPrice");
		// check pic
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < modifyproductBean.getPics().size(); i++) {
			Logger.comment("验证pictures");
			Logger.verifyEquals(modifyproductBean.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,
				modifyproductBean.getUserId());

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		modifyproductBean.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, modifyproductBean.getUserId()).stream()
				.map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(modifyproductBean.getDescription()), "验证Description");

		// check Ymt_ProductDeliveryTemplate
		if (modifyproductBean.getFreightTemplateId() != 0) {
			Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(productId).get(0);
			if (Integer.parseInt(deliMap.get("Status").toString()) > -1) {
				Logger.verifyEquals(modifyproductBean.getUserId(), Integer.parseInt(deliMap.get("SellerId").toString()),
						"验证sellerId");
				Logger.verifyEquals(modifyproductBean.getFreightTemplateId(),
						Integer.parseInt(deliMap.get("TemplateId").toString()), "验证TemplateId");
				Logger.verifyEquals(modifyproductBean.getCatalogStatus(),
						Integer.parseInt(deliMap.get("CatalogStatus").toString()), "验证CatalogStatus");
				Logger.verifyEquals(1, Integer.parseInt(deliMap.get("Status").toString()), "验证Status");
				Logger.verifyEquals(productId, deliMap.get("ProductId").toString(), "验证ProductId");
			}
		}

		modifyproductBean.getCatalogList().forEach(p -> {
			try {
				if (p.getCatalogId() != null) {
					YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(p.getCatalogId());
					YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper
							.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
					Logger.verifyEquals(p.getStock(), rootYmtCatalogsI.getiNum(), "验证stock");
					// Logger.verifyEquals(p.getSku(),ymtCatalogsI.getsSKU(),"验证sku");
					Logger.verifyEquals(p.getPic(), ymtCatalogsI.getsPicUrl(), "验证pic");
					Logger.verifyEquals(p.getWeight(), ymtCatalogsI.getWeight().doubleValue(), "验证Weight");
					Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().setScale(1).doubleValue(),
							"验证directPrice");

					List<Map<String, Object>> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId());
					map.forEach(x -> {
						p.getPropertyList().forEach(o -> {
							if (o.getValue().equals(x.get("sCategoryAttribute").toString())) {
								Logger.verifyEquals(o.getName(), x.get("sProductProperty").toString(), "验证name");
								Logger.verifyEquals(o.getPic(), x.get("sPicUrl").toString(), "验证pic");
								Logger.verifyEquals(o.getSubType(), x.get("SubType").toString(), "验证SubType");
							}
						});
					});

					if (p.getAgentPriceList() != null && modifyproductBean.getSetAgentPrice()) {
						p.getAgentPriceList().forEach(x -> {
							AgentPricePo agentPricePo = ymtProductsIWapper
									.selectAgentPriceByCatalogId(p.getCatalogId(), x.getAgentTypeId()).get(0);
							Logger.verifyEquals(x.getAgentPrice(), agentPricePo.getAgentPrice(), "验证agentPrice");
						});
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
	}

	public static void checkImportantAgentProduct(String productId, ImportAgentProductBean importAgentProductBean,
			boolean isVip) throws Exception {
		Map<String, Object> pmap = ipm.selectProductByProdId(productId);
		Logger.debug(pmap);
		// check product
		Logger.verifyEquals(importAgentProductBean.getUserId(), Integer.parseInt(pmap.get("iUserId").toString()),
				"验证SellerId");
		Logger.verifyEquals(importAgentProductBean.getTitle(), pmap.get("sProduct").toString(), "验证productName");
		Logger.verifyEquals(importAgentProductBean.getRemark(), pmap.get("Remark").toString(), "验证商品描述");
		Logger.verifyEquals(importAgentProductBean.getPics().get(0), pmap.get("sPicUrl").toString(), "验证商品主图（首图）");
		Logger.verifyEquals(0, Integer.parseInt(pmap.get("iAction").toString()), "验证action");
		Logger.verifyEquals(3, Integer.parseInt(pmap.get("ProductType").toString()), "验证商品类型");
		Logger.verifyEquals(0, Integer.parseInt(pmap.get("CardInfo").toString()), "验证商品物流方式中身份信息是否提供");

		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dAddTime"), 120, "验证商品发布时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) pmap.get("dLastUpdate"), 120, "验证商品最后更新时间");

		// check pic
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < importAgentProductBean.getPics().size(); i++) {
			Logger.verifyEquals(importAgentProductBean.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,
				importAgentProductBean.getUserId());

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		importAgentProductBean.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, importAgentProductBean.getUserId())
				.stream().map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(importAgentProductBean.getDescription()), "验证Description");

		// check catalog
		List<YmtCatalogsI> ymtCatalogsIList = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
		Logger.debug(ymtCatalogsIList);
		importAgentProductBean.getCatalogList().forEach(p -> {
			for (YmtCatalogsI ymtCatalogsI : ymtCatalogsIList) {
				// check Ymt_CatalogSetAttributes
				List<Map<String, Object>> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId());
				map.forEach(x -> {
					p.getPropertyList().forEach(o -> {
						if (o.getValue().equals(x.get("sCategoryAttribute").toString())) {
							Logger.verifyEquals(o.getName(), x.get("sProductProperty").toString(), "验证name");
							Logger.verifyEquals(o.getPic(), x.get("sPicUrl").toString(), "验证pic");
							Logger.verifyEquals(o.getSubType(), x.get("SubType").toString(), "验证SubType");
						}
					});
				});

				if (ymtCatalogsI.getsSKU().equals(p.getSku())) {
					Logger.debug("验证规格");
					Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(), "验证直销价");
					Logger.verifyEquals(0, ymtCatalogsI.getiNum(), "验证库存");
					Logger.verifyEquals(0, ymtCatalogsI.getiAction(), "验证action");
					Logger.verifyEquals(p.getParentCatalogId(), ymtCatalogsI.getParentCatalogId(), "验证parentId");
					try {
						YmtCatalogsI ymtCatalogsI1 = ymtCatalogsIWapper
								.selectCatalogsByCatalogId(p.getParentCatalogId());
						Logger.verifyEquals(ymtCatalogsI1.getRootCatalogId(), ymtCatalogsI.getRootCatalogId(),
								"验证rootCatalogId");
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					AssertService.assertTime(YMTDateUtil.getDate(), (Date) ymtCatalogsI.getdAddTime(), 120,
							"验证商品规格的发布时间");
				}
				// check ymt_AgentPrice
				if (p.getAgentPriceList() != null) {
					p.getAgentPriceList().forEach(x -> {
						List<AgentPricePo> agentPricePos = ymtProductsIWapper
								.selectAgentPriceByCatalogId(ymtCatalogsI.getsCatalogId(), x.getAgentTypeId());
						agentPricePos.forEach(c -> {
							if (x.getAgentPrice() == c.getAgentPrice()) {
								Logger.debug("验证代理价格");
								Logger.verifyEquals(x.getAgentPrice(), c.getAgentPrice(), "验证代理价格");
								Logger.verifyEquals(productId, c.getProductId(), "验证productId");
								Logger.verifyEquals(importAgentProductBean.getUserId(), c.getUserId(), "验证UserId");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getCreateTime(), 120,
										"验证创建时间");
								AssertService.assertTime(YMTDateUtil.getDate(), (Date) c.getUpdateTime(), 120,
										"验证更新时间");
							}
						});
					});
				}
			}
		});

		// check AgentProducts
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		Logger.debug(agentProductPo);
		Logger.verifyEquals(importAgentProductBean.getUserId(), agentProductPo.getUserId(), "验证UserId");
		if (isVip) {
			Logger.verifyEquals(2, agentProductPo.getAgentType(), "验证代理类型");
		} else {
			Logger.verifyEquals(1, agentProductPo.getAgentType(), "验证代理类型");
		}
		
		List<AgentPricePo> agentPricePos = ymtProductsIWapper.selectAgentPriceByProductIdAndUserId(productId,
				importAgentProductBean.getUserId());
		if (importAgentProductBean.getCatalogList().get(0).getAgentPriceList() != null && agentPricePos.size() > 1) {
			Logger.verifyEquals(true, agentProductPo.isSetAgentPrice(), "验证是否允许下级代理");
		} else {
			Logger.verifyEquals(false, agentProductPo.isSetAgentPrice(), "验证是否允许下级代理");
		}
		Logger.verifyEquals(0, agentProductPo.getStatus(), "验证商品是上架状态");
		Logger.verifyEquals(0, agentProductPo.getInfoProgress(), "验证商品信息完善进度");
		Logger.verifyEquals(0, agentProductPo.getAction(), "验证商品action");
		Logger.verifyEquals(importAgentProductBean.getParentUserId(), agentProductPo.getParentUserId(),
				"验证商品parentUserId");
		Logger.verifyEquals(importAgentProductBean.getParentProductId(), agentProductPo.getParentProductId(),
				"验证商品parentProductId");
		AgentProductPo agentProductPo1 = ymtProductsIWapper
				.selectAgentProductByProductId(importAgentProductBean.getParentProductId());
		Logger.verifyEquals(agentProductPo1.getRootUserId(), agentProductPo.getRootUserId(), "验证商品rootUserId");
		Logger.verifyEquals(agentProductPo1.getRootProductId(), agentProductPo.getRootProductId(), "验证商品rootProductId");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) agentProductPo.getCreateTime(), 120, "验证创建时间");
		AssertService.assertTime(YMTDateUtil.getDate(), (Date) agentProductPo.getUpdateTime(), 120, "验证更新时间");
	}

	public static void checkProductList(GetProductListBean getproductlistBean, List<ProductListDto> productListDtoList)
			throws IOException {
		productListDtoList.forEach(p -> {
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(p.getProductId());
			AgentProductPo rootAgentProduct = ymtProductsIWapper
					.selectAgentProductByProductId(agentProductPo.getRootProductId());
			try {
				YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(p.getProductId()).get(0);
				YmtProductsI rootYmtProductsI = ymtProductsIWapper
						.selectProductByProductId(rootAgentProduct.getProductId()).get(0);
				Logger.verifyEquals(getproductlistBean.getUserId(), p.getUserId(), "验证userId");
				Logger.verifyEquals(p.getAgentType(), agentProductPo.getAgentType(), "验证agentType");
				Logger.verifyEquals(p.getTitle(), ymtProductsI.getsProduct(), "验证title");
				List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(p.getProductId());
				Logger.verifyEquals(p.getPics().size(), pictures.size() + 1, "验证pics");
				Logger.verifyEquals(p.getCompressPics(), null, "验证compressPics");
				Logger.verifyEquals(p.getBrandName(), rootYmtProductsI.getsBrand(), "验证brandName");

				GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(p.getCurrency().getCode());
				Logger.verifyEquals(p.getCurrency().getCode(), currencyConfigResp.getCurrency(), "验证code");
				Logger.verifyEquals(p.getCurrency().getName(), currencyConfigResp.getName(), "验证name");
				Logger.verifyEquals(p.getCurrency().getSymbol(), currencyConfigResp.getMark(), "验证Symbol");
//				Logger.verifyEquals(p.getCurrency().getExchangeRate(), currencyConfigResp.getExchangeRmbRate(),
//						"验证ExchangeRmbRate");

				if (p.getThirdCategoryId() != null) {
					CategoryDtoV2 categoryDtoV2 = ymtProductsIWapper
							.selectCategoryByThirdCategoryId(rootYmtProductsI.getiThirdCategoryId()).get(0);
					Logger.verifyEquals(p.getCategoryId(), categoryDtoV2.getFirstCategoryId(), "验证categoryId");
					Logger.verifyEquals(p.getSecondCategoryId(), categoryDtoV2.getSecondCategoryId(),
							"验证secondCategoryId");
					Logger.verifyEquals(p.getThirdCategoryId(), categoryDtoV2.getThirdCategoryId(),
							"验证thirdCategoryId");
					String categoryName = categoryDtoV2.getFirstCategoryName() + "-"
							+ categoryDtoV2.getSecondCategoryName() + "-" + categoryDtoV2.getThirdCategoryName();
					Logger.verifyEquals(p.getCategoryName(), categoryName, "验证categoryName");
				}
				Logger.verifyEquals(p.getCatalogStatus(), rootYmtProductsI.getiCatalogStatus(), "验证catalogStatus");
				Logger.verifyEquals(p.getCardInfo(), rootYmtProductsI.getCardInfo(), "验证cardInfo");
				Logger.verifyEquals(p.getRemark(), rootYmtProductsI.getRemark(), "验证remark");
				Logger.verifyEquals(p.getInfoProgress(), agentProductPo.getInfoProgress(), "验证infoProgress");

				if (ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId()).size() > 0) {
					Logger.debug("delimap:"
							+ ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId()));
					Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId())
							.get(0);
					freight_templateWapper templateWapper = new freight_templateWapper();
					freight_template template = templateWapper
							.selectByPrimaryKey(Integer.parseInt(deliMap.get("TemplateId").toString()));
					Logger.verifyEquals(p.getFreightTemplateName(), template.getTemplateName(), "验证TemplateName");
				} else {
					Logger.verifyEquals(p.getFreightTemplateName(), "包邮", "验证TemplateName");
				}

				if (agentProductPo.getAgentType() == 0) {
					Logger.verifyEquals(p.getAgentSource(), "自采商品", "验证agentSource");
				}

				p.getCatalogList().forEach(x -> {
					try {
						YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(x.getCatalogId());
						YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper
								.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
						Logger.verifyEquals(x.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(),
								"验证directPrice");
						Logger.verifyEquals(x.getSku(), ymtCatalogsI.getsSKU(), "验证sku");
						if (agentProductPo.getAgentType() == 0) {
							Logger.verifyEquals(x.getStockInfo(), "库存 " + ymtCatalogsI.getiNum(), "验证stockInfo");
							Logger.verifyEquals(x.getAgentPrice(), 0.0, "验证agentPrice");
							Logger.verifyEquals(x.getProfit(), 0.0, "验证profit");
							List<Map> maps = ymtCatalogsIWapper.selectCatalogSetAttributesByCatalogId(x.getCatalogId());
							List<String> sCategoryAttribute = maps.stream()
									.map(o -> o.get("sCategoryAttribute").toString()).collect(Collectors.toList());
							String s = sCategoryAttribute.get(0);
							for (int i = 1; i < sCategoryAttribute.size(); i++) {
								s = s + " + " + sCategoryAttribute.get(i);
							}
							Logger.verifyEquals(x.getPropertyValue(), s, "验证propertyValue");
						} else {
							if (rootYmtCatalogsI.getiNum() > 10) {
								Logger.verifyEquals(x.getStockInfo(), "库存充足", "验证stockInfo");
							} else {
								Logger.verifyEquals(x.getStockInfo(), "库存紧张(不足10件)", "验证stockInfo");
							}
							List<PriceModel> priceModels = ymtProductsIWapper.selectAgentProductPrice(x.getCatalogId());
							if (priceModels.get(0).getSalePrice().doubleValue() > priceModels.get(0).getBuyingPrice()) {
								Logger.verifyEquals(x.getAgentPrice(), priceModels.get(0).getBuyingPrice(),
										"验证agentPrice");
								Logger.verifyEquals(x.getProfit(), priceModels.get(0).getSalePrice().doubleValue()
										- priceModels.get(0).getBuyingPrice(), "验证profit");
							} else {
								Logger.verifyEquals(x.getAgentPrice(), priceModels.get(0).getBuyingPrice(),
										"验证agentPrice");
								Logger.verifyEquals(x.getProfit(), 0.0, "验证profit");
							}
							List<Map> maps = ymtCatalogsIWapper.selectCatalogSetAttributesByCatalogId(x.getCatalogId());
							List<String> sCategoryAttribute = maps.stream()
									.map(o -> o.get("sCategoryAttribute").toString()).collect(Collectors.toList());
							String s = sCategoryAttribute.get(0);
							for (int i = 1; i < sCategoryAttribute.size(); i++) {
								s = s + " + " + sCategoryAttribute.get(i);
							}
							Logger.verifyEquals(x.getPropertyValue(), s, "验证propertyValue");
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		});
	}

	public static void checkProductListNotsku(GetProductListBean getproductlistBean,
			List<ProductListDto> productListDtoList) throws IOException {
		productListDtoList.forEach(p -> {
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(p.getProductId());
			AgentProductPo rootAgentProduct = ymtProductsIWapper
					.selectAgentProductByProductId(agentProductPo.getRootProductId());
			try {
				YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(p.getProductId()).get(0);
				YmtProductsI rootYmtProductsI = ymtProductsIWapper
						.selectProductByProductId(rootAgentProduct.getProductId()).get(0);
				Logger.verifyEquals(getproductlistBean.getUserId(), p.getUserId(), "验证userId");
				Logger.verifyEquals(p.getAgentType(), agentProductPo.getAgentType(), "验证agentType");
				Logger.verifyEquals(p.getTitle(), ymtProductsI.getsProduct(), "验证title");
				List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(p.getProductId());
				Logger.verifyEquals(p.getPics().size(), pictures.size() + 1, "验证pics");
				Logger.verifyEquals(p.getCompressPics(), null, "验证compressPics");
				Logger.verifyEquals(p.getBrandName(), rootYmtProductsI.getsBrand(), "验证brandName");

				GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(p.getCurrency().getCode());
				Logger.verifyEquals(p.getCurrency().getCode(), currencyConfigResp.getCurrency(), "验证code");
				Logger.verifyEquals(p.getCurrency().getName(), currencyConfigResp.getName(), "验证name");
				Logger.verifyEquals(p.getCurrency().getSymbol(), currencyConfigResp.getMark(), "验证Symbol");
				Logger.verifyNotNull( currencyConfigResp.getExchangeRmbRate(),
						"验证ExchangeRmbRate");

				if (p.getThirdCategoryId() != null) {
					CategoryDtoV2 categoryDtoV2 = ymtProductsIWapper
							.selectCategoryByThirdCategoryId(rootYmtProductsI.getiThirdCategoryId()).get(0);
					Logger.verifyEquals(p.getCategoryId(), categoryDtoV2.getFirstCategoryId(), "验证categoryId");
					Logger.verifyEquals(p.getSecondCategoryId(), categoryDtoV2.getSecondCategoryId(),
							"验证secondCategoryId");
					Logger.verifyEquals(p.getThirdCategoryId(), categoryDtoV2.getThirdCategoryId(),
							"验证thirdCategoryId");
					String categoryName = categoryDtoV2.getFirstCategoryName() + "-"
							+ categoryDtoV2.getSecondCategoryName() + "-" + categoryDtoV2.getThirdCategoryName();
					Logger.verifyEquals(p.getCategoryName(), categoryName, "验证categoryName");
				}
				Logger.verifyEquals(p.getCatalogStatus(), rootYmtProductsI.getiCatalogStatus(), "验证catalogStatus");
				Logger.verifyEquals(p.getCardInfo(), rootYmtProductsI.getCardInfo(), "验证cardInfo");
				Logger.verifyEquals(p.getRemark(), rootYmtProductsI.getRemark(), "验证remark");
				Logger.verifyEquals(p.getInfoProgress(), agentProductPo.getInfoProgress(), "验证infoProgress");

				if (ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId()).size() > 0) {
					Logger.debug("delimap:"
							+ ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId()));
					Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootAgentProduct.getProductId())
							.get(0);
					freight_templateWapper templateWapper = new freight_templateWapper();
					freight_template template = templateWapper
							.selectByPrimaryKey(Integer.parseInt(deliMap.get("TemplateId").toString()));
					Logger.verifyEquals(p.getFreightTemplateName(), template.getTemplateName(), "验证TemplateName");
				} else {
					Logger.verifyEquals(p.getFreightTemplateName(), "包邮", "验证TemplateName");
				}

				if (agentProductPo.getAgentType() == 0) {
					Logger.verifyEquals(p.getAgentSource(), "自采商品", "验证agentSource");
				}

				p.getCatalogList().forEach(x -> {
					try {
						YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(x.getCatalogId());
						YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper
								.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
						Logger.verifyEquals(x.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(),
								"验证directPrice");
						// Logger.verifyEquals(x.getSku(),ymtCatalogsI.getsSKU(),"验证sku");
						if (agentProductPo.getAgentType() == 0) {
							Logger.verifyEquals(x.getStockInfo(), "库存 " + ymtCatalogsI.getiNum(), "验证stockInfo");
							Logger.verifyEquals(x.getAgentPrice(), 0.0, "验证agentPrice");
							Logger.verifyEquals(x.getProfit(), 0.0, "验证profit");
							List<Map> maps = ymtCatalogsIWapper.selectCatalogSetAttributesByCatalogId(x.getCatalogId());
							List<String> sCategoryAttribute = maps.stream()
									.map(o -> o.get("sCategoryAttribute").toString()).collect(Collectors.toList());
							String s = sCategoryAttribute.get(0);
							for (int i = 1; i < sCategoryAttribute.size(); i++) {
								s = s + " + " + sCategoryAttribute.get(i);
							}
							Logger.verifyEquals(x.getPropertyValue(), s, "验证propertyValue");
						} else {
							if (rootYmtCatalogsI.getiNum() > 10) {
								Logger.verifyEquals(x.getStockInfo(), "库存充足", "验证stockInfo");
							} else {
								Logger.verifyEquals(x.getStockInfo(), "库存紧张(不足10件)", "验证stockInfo");
							}
							List<PriceModel> priceModels = ymtProductsIWapper.selectAgentProductPrice(x.getCatalogId());
							if (priceModels.get(0).getSalePrice().doubleValue() > priceModels.get(0).getBuyingPrice()) {
								Logger.verifyEquals(x.getAgentPrice(), priceModels.get(0).getBuyingPrice(),
										"验证agentPrice");
								Logger.verifyEquals(x.getProfit(), priceModels.get(0).getSalePrice().doubleValue()
										- priceModels.get(0).getBuyingPrice(), "验证profit");
							} else {
								Logger.verifyEquals(x.getAgentPrice(), priceModels.get(0).getBuyingPrice(),
										"验证agentPrice");
								Logger.verifyEquals(x.getProfit(), 0.0, "验证profit");
							}
							List<Map> maps = ymtCatalogsIWapper.selectCatalogSetAttributesByCatalogId(x.getCatalogId());
							List<String> sCategoryAttribute = maps.stream()
									.map(o -> o.get("sCategoryAttribute").toString()).collect(Collectors.toList());
							String s = sCategoryAttribute.get(0);
							for (int i = 1; i < sCategoryAttribute.size(); i++) {
								s = s + " + " + sCategoryAttribute.get(i);
							}
							Logger.verifyEquals(x.getPropertyValue(), s, "验证propertyValue");
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		});
	}

	public static void checkProductDetail(String productId, ProductDetailsDto productDetailsDto)
			throws InterruptedException {
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		AgentProductPo rootagentProductPo = ymtProductsIWapper
				.selectAgentProductByProductId(agentProductPo.getRootProductId());
		Logger.verifyEquals(productDetailsDto.getAgentType(), agentProductPo.getAgentType(), "验证AgentType");
//		Logger.verifyEquals(productDetailsDto.getStatus(), agentProductPo.getStatus(), "验证Status");
		Logger.verifyEquals(productDetailsDto.getInfoProgress(), agentProductPo.getInfoProgress(), "验证infoProgress");
		productDetailsDto.getChannelCurrencies().forEach(p -> {
			try {
				GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(p.getCode());
				Logger.verifyEquals(p.getCode(), currencyConfigResp.getCurrency(), "验证code");
				Logger.verifyEquals(p.getSymbol(), currencyConfigResp.getMark(), "验证mark");
				Logger.verifyEquals(p.getName(), currencyConfigResp.getName(), "验证name");
//				Logger.verifyEquals(p.getExchangeRate(), currencyConfigResp.getExchangeRmbRate(), "验证ExchangeRate");
			} catch (IOException e) {
				e.printStackTrace();
			}

		});

		List<Map<String, Object>> maps = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,
				productDetailsDto.getUserId());

		String pictureUrl = maps.stream().map(x -> x.get("PictureUrl").toString()).collect(Collectors.toList())
				.toString();
		productDetailsDto.getDescPicList().forEach(p -> {
			Logger.verifyEquals(true, pictureUrl.contains(p), "验证DescPicList");
		});
		String maps1 = ipm.selectDescConfigWordByProdIdAndSellerId(productId, productDetailsDto.getUserId()).stream()
				.map(x -> x.get("WordContent").toString()).collect(Collectors.toList()).toString();
		Logger.verifyEquals(true, maps1.contains(productDetailsDto.getDescription()), "验证Description");

		YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId).get(0);
		YmtProductsI rootProductsI = ymtProductsIWapper.selectProductByProductId(rootagentProductPo.getProductId())
				.get(0);

		Logger.verifyEquals(productDetailsDto.getTitle(), ymtProductsI.getsProduct(), "验证title");
		Logger.verifyEquals(productDetailsDto.getBrandName(), rootProductsI.getsBrand(), "验证brandName");
		Logger.verifyEquals(productDetailsDto.getBrandId(), rootProductsI.getiBrandId(), "验证brandId");
		Logger.verifyEquals(productDetailsDto.getSecondCategoryId(), rootProductsI.getiCategoryId(),
				"验证secondCategoryId");
		Logger.verifyEquals(productDetailsDto.getThirdCategoryId(), rootProductsI.getiThirdCategoryId(),
				"验证thirdCategoryId");

		Map sm = ymtProductCategoryWapper.getGodProductCategoryByCategoryId(productDetailsDto.getSecondCategoryId()).get(0);
		Map tm = ymtProductCategoryWapper.getGodProductCategoryByCategoryId(productDetailsDto.getThirdCategoryId()).get(0);
		Logger.verifyEquals(true, productDetailsDto.getCategoryName().contains(sm.get("sCategory").toString()),
				"验证categoryName");
		Logger.verifyEquals(true, productDetailsDto.getCategoryName().contains(tm.get("sCategory").toString()),
				"验证categoryName");

		Logger.verifyEquals(productDetailsDto.getCatalogStatus(), rootProductsI.getiCatalogStatus(), "验证catalogStatus");
		Logger.verifyEquals(productDetailsDto.getCardInfo(), rootProductsI.getCardInfo(), "验证cardInfo");
		Logger.verifyEquals(productDetailsDto.getRemark(), rootProductsI.getRemark(), "验证remark");

		if (ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootagentProductPo.getProductId()).size() > 0) {
			Logger.debug("delimap:"
					+ ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootagentProductPo.getProductId()));
			Map deliMap = ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootagentProductPo.getProductId())
					.get(0);
			freight_templateWapper templateWapper = new freight_templateWapper();
			freight_template template = templateWapper
					.selectByPrimaryKey(Integer.parseInt(deliMap.get("TemplateId").toString()));
			Logger.verifyEquals(productDetailsDto.getFreightTemplateName(), template.getTemplateName(),
					"验证TemplateName");
		}

		if (rootagentProductPo.getRootProductId().equals(productId)) {
			Logger.verifyEquals(productDetailsDto.getAgentSource(), "自采商品", "验证agentSource");
		}

		if (rootProductsI.getiDeliveryType() == 999) {
			Logger.verifyEquals(productDetailsDto.getCatalogStatusText(), "其他物流", "验证catalogStatusText");
		} else {
			Logger.verifyEquals(productDetailsDto.getCatalogStatusText(), "海外物流", "验证catalogStatusText");
		}
		List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
		for (int i = 0; i < productDetailsDto.getPics().size(); i++) {
			Logger.verifyEquals(productDetailsDto.getPics().get(i), pictures.get(i).get("sOriUrl").toString(),
					"验证商品图片地址");
			Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date) pictures.get(i).get("dAddTime"), 120, "验证商品图片的添加时间");
		}

		List<AgentPricePo> agentPricePos = ymtProductsIWapper.selectAgentPriceByProductIdAndUserId(productId,
				agentProductPo.getUserId());
		if (agentPricePos != null) {
			agentPricePos.forEach(p -> {
				productDetailsDto.getAgentPriceList().forEach(x -> {
					if (p.getAgentTypeId() == x.getAgentType()) {
						try {
							agent_type agentType = agentTypeWapper
									.selectby(MapUtil.hashMap("agentType", p.getAgentTypeId())).get(0);
							Logger.verifyEquals(x.getAgentTypeName(), agentType.getTypeTitle(), "验证agentTypeName");
							x.getCatalogPriceList().forEach(v -> {
								List<AgentPricePo> agentPricePoList = ymtProductsIWapper
										.selectAgentPriceByAgentType(x.getAgentType());
								agentPricePoList.forEach(c -> {
									if (v.getCatalogId() != null && v.getCatalogId().equals(c.getCatalogId())) {
										Logger.verifyEquals(v.getAgentPrice(), c.getAgentPrice(), "验证agentPrice");
									}
								});
							});
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				});
			});
		}
	}

	/**
	 * 
	 */
	public static AddactivityBean initProductaddactivity(int sellerId, String productId) throws ClientProtocolException, IOException {
		//创建限时抢购活动
		List<String> catalogList =new ArrayList<String>();
		ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(sellerId,productId);
		selectProductDetails.getCatalogList().forEach(a->{
	 		catalogList.add(a.getCatalogId());
	 	});
		
		AddactivityBean addactivityBean = new AddactivityBean();
		
		addactivityBean.setActivityId(null);
		addactivityBean.setSellerId(sellerId);
		addactivityBean.setCurUserId(sellerId);

		// 创建开始结束时间 一天前---十天后
		addactivityBean.setBeginTime(YMTDateUtil.getBeforeOrNextDate(-1));
		addactivityBean.setEndTime(YMTDateUtil.getBeforeOrNextDate(10));
		
		addactivityBean.setName("神器显示抢购活动_" + TestDataManager.getRandomIntNum(5));
		addactivityBean.setLimitType(1);// 限购类型，1.不限购，2.活动内每人每商品限购
		addactivityBean.setLimitNum(10);// 限购数量
		addactivityBean.setActivityType(1);// 活动类型，1.限时抢
		addactivityBean.setDiscountType(0);
		addactivityBean.setPreviewTime(0);
		addactivityBean.setStockType(0);
		
		List<ProductAgentBean> lists = new ArrayList<ProductAgentBean>();
		ProductAgentBean productAgentBean = new ProductAgentBean();
		productAgentBean.setProductId(productId);
		List<CatalogAgentBean> list1 = new ArrayList<CatalogAgentBean>();
		catalogList.forEach(e -> {
			CatalogAgentBean c = new CatalogAgentBean();
			c.setCatalogId(e);
			c.setDiscount(new BigDecimal("2"));// 折扣，例如：8.5折，值为：8.5
			c.setDiscountPrice(new BigDecimal("8"));
			c.setActivityStock(0);
			list1.add(c);
		});
		productAgentBean.setCatalogList(list1);
		lists.add(productAgentBean);
		addactivityBean.setProductList(lists);
		return addactivityBean;
	}
	
	
	
	/**
	 * 添加、编辑 活动库存的活动
	 * 
	 * @param sellerId
	 *            商户id
	 * @param productId
	 *            商品id
	 * @param StockType
	 *            0使用规格库存，1锁定活动库存
	 * @param activityStock
	 *            null或者活动库存
	 * @param useSubCode
	 * 			  是否使用子码
	 */
	public static AddactivityBean initProductaddactivity(int sellerId,
			String productId, Integer StockType, Integer activityStock, Boolean useSubCode)
			throws ClientProtocolException, IOException {
		// 创建限时抢购活动
		
		ProductDetailsDto selectProductDetails = AddAgentProductCallService
				.selectProductDetails(sellerId, productId);

		AddactivityBean addactivityBean = new AddactivityBean();

		addactivityBean.setActivityId(null);
		addactivityBean.setSellerId(sellerId);
		addactivityBean.setCurUserId(sellerId);

		// 创建开始结束时间 一天前---十天后
		addactivityBean.setBeginTime(YMTDateUtil.getBeforeOrNextDate(-1));
		addactivityBean.setEndTime(YMTDateUtil.getBeforeOrNextDate(10));

		addactivityBean.setName("神器显示抢购活动_"
				+ TestDataManager.getRandomIntNum(5));
		addactivityBean.setLimitType(1);// 限购类型，1.不限购，2.活动内每人每商品限购
		addactivityBean.setLimitNum(10);// 限购数量
		addactivityBean.setActivityType(1);// 活动类型，1.限时抢
		addactivityBean.setDiscountType(0);
		addactivityBean.setPreviewTime(0);
		addactivityBean.setStockType(StockType);

		List<ProductAgentBean> lists = new ArrayList<ProductAgentBean>();
		
		ProductAgentBean productAgentBean = new ProductAgentBean();
		
		productAgentBean.setProductId(productId);
		
		if (useSubCode)
			productAgentBean.setUseSubCode(useSubCode);
		
		List<CatalogAgentBean> list1 = new ArrayList<CatalogAgentBean>();
		
		selectProductDetails.getCatalogList().forEach(detailsCatalogDto -> {
			
			CatalogAgentBean c = new CatalogAgentBean();
			
			c.setCatalogId(detailsCatalogDto.getCatalogId());
//			c.setSubCode(detailsCatalogDto.getSubCodeList().get(0).getCode());
			c.setDiscount(new BigDecimal("2"));// 折扣，例如：8.5折，值为：8.5
			c.setDiscountPrice(new BigDecimal(8.0));
			c.setActivityStock(activityStock == null ? 0 : activityStock);
			c.setSubCodeId(detailsCatalogDto.getSubCodeList()
					.size() == 0 ? 0 : detailsCatalogDto.getSubCodeList().get(0).getId());
			
			list1.add(c);
		});

		productAgentBean.setCatalogList(list1);
		lists.add(productAgentBean);
		addactivityBean.setProductList(lists);

		return addactivityBean;
	}
	
	/**
	 *  添加、编辑 活动库存的活动
	 * @param sellerId  商户id
	 * @param productId  商品id
	 * @param StockType 0使用规格库存，1锁定活动库存
	 * @param activityStock  null或者活动库存
	 */
	public static AddactivityBean initAgenttActivity(int sellerId, String productId,Integer StockType,Integer activityStock) throws ClientProtocolException, IOException {
		//创建限时抢购活动
		List<String> catalogList =new ArrayList<String>();
		ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(sellerId,productId);
		selectProductDetails.getCatalogList().forEach(a->{
	 		catalogList.add(a.getCatalogId());
	 	});
		
		AddactivityBean addactivityBean = new AddactivityBean();
		
		addactivityBean.setActivityId(null);
		addactivityBean.setSellerId(sellerId);
		addactivityBean.setCurUserId(sellerId);
		addactivityBean.setAllowAgent(true);
		// 创建开始结束时间 一天前---十天后
		addactivityBean.setBeginTime(YMTDateUtil.getBeforeOrNextDate(-1));
		addactivityBean.setEndTime(YMTDateUtil.getBeforeOrNextDate(10));

		addactivityBean.setName("神器显示抢购活动_" + TestDataManager.getRandomIntNum(5));
		addactivityBean.setLimitType(1);// 限购类型，1.不限购，2.活动内每人每商品限购
		addactivityBean.setLimitNum(10);// 限购数量
		addactivityBean.setActivityType(3);// 活动类型，1.限时抢
		addactivityBean.setDiscountType(0);
		addactivityBean.setPreviewTime(0);
		addactivityBean.setStockType(StockType);
		
		List<ProductAgentBean> lists = new ArrayList<ProductAgentBean>();
		ProductAgentBean productAgentBean = new ProductAgentBean();
		productAgentBean.setProductId(productId);
		List<CatalogAgentBean> list1 = new ArrayList<CatalogAgentBean>();
		catalogList.forEach(e -> {
			CatalogAgentBean c = new CatalogAgentBean();
			c.setCatalogId(e);
			c.setDiscount(new BigDecimal("2"));// 折扣，例如：8.5折，值为：8.5
			c.setDiscountPrice(new BigDecimal(8.0));
			c.setActivityStock(activityStock==null?0:activityStock);
			list1.add(c);
		});
		productAgentBean.setCatalogList(list1);
		lists.add(productAgentBean);
		addactivityBean.setProductList(lists);
		return addactivityBean;
	}
	

	/**
	 * 限时抢
	 * @param addactivityBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer agentProductaddactivity(AddactivityBean addactivityBean)
			throws ClientProtocolException, IOException {
		AddactivityCall addactivityCall = new AddactivityCall();
		addactivityCall.setData(addactivityBean);
		addactivityCall.callService();
		return addactivityCall.getJsonObject().get("data").getAsJsonObject().get("activityId").getAsInt();

	}
   /**
    * 限时折扣-终止活动
    * @param sellerId
    * @param activityId
    * @return
    * @throws ClientProtocolException
    * @throws IOException
    */
	public static endactivityCall endactivity(Integer sellerId,Integer activityId)
			throws ClientProtocolException, IOException {
		endactivityCall endactivityCall = new endactivityCall();
		endactivityBean endactivityBean=new endactivityBean();
		endactivityBean.setCurUserId(sellerId);
		endactivityBean.setSellerId(sellerId);
		endactivityBean.setActivityId(activityId);
		
		endactivityCall.setData(endactivityBean);
		endactivityCall.callService();
		return endactivityCall;

	}
	
	public static void checkSelectionList(SelectionListBean selectionlistBean,
			List<SelectProductListDto> selectProductListDtos) throws IOException {
		selectProductListDtos.forEach(p -> {
			try {
				AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(p.getProductId());
				AgentProductPo rootagentProductPo = ymtProductsIWapper
						.selectAgentProductByProductId(agentProductPo.getRootProductId());

				YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(p.getProductId()).get(0);
				YmtProductsI rootymtProductsI = ymtProductsIWapper
						.selectProductByProductId(rootagentProductPo.getProductId()).get(0);
				Logger.verifyEquals(p.getTitle(), ymtProductsI.getsProduct(), "验证title");
				Logger.verifyEquals(p.getBrandName(), rootymtProductsI.getsBrand(), "验证brandName");

				GetCurrencyConfigResp currencyConfigResp = getCurrencyConfigResp(p.getCurrency().getCode());
				Logger.verifyEquals(p.getCurrency().getCode(), currencyConfigResp.getCurrency(), "验证code");
				Logger.verifyEquals(p.getCurrency().getName(), currencyConfigResp.getName(), "验证name");
				Logger.verifyEquals(p.getCurrency().getSymbol(), currencyConfigResp.getMark(), "验证mark");
//				Logger.verifyEquals(p.getCurrency().getExchangeRate(), currencyConfigResp.getExchangeRmbRate(),
//						"验证ExchangeRmbRate");

				Logger.verifyEquals(p.getAgentType(), agentProductPo.getAgentType(), "验证agentType");
				String rootProductId = ymtProductsIWapper.selectAgentProductByProductId(p.getProductId())
						.getRootProductId();
				List<Integer> userIds = ymtProductsIWapper.selectAgentProductByRootProductId(rootProductId).stream()
						.filter(x -> x.getAction() == 0).map(x -> x.getUserId()).collect(Collectors.toList());
				Logger.debug("userIds:" + userIds);
				Logger.debug("productId:" + p.getProductId());
				if (userIds.contains(selectionlistBean.getUserId())) {
					Logger.verifyEquals(true, p.isExistsShop(), "验证existsShop");
				} else {
					Logger.verifyEquals(false, p.isExistsShop(), "验证existsShop");
				}

				Logger.debug("rootymtProductsI:" + rootymtProductsI);
				if (ymtProductCategoryWapper.getGodProductCategoryByCategoryId(rootymtProductsI.getiCategoryId())
						.size() != 0) {
					Map cm = ymtProductCategoryWapper.getGodProductCategoryByCategoryId(rootymtProductsI.getiCategoryId())
							.get(0);
					Logger.verifyEquals(true, p.getCategoryName().contains(cm.get("sCategory").toString()),
							"验证categoryName");
				}
				if (ymtProductCategoryWapper.getGodProductCategoryByCategoryId(rootymtProductsI.getiThirdCategoryId())
						.size() != 0) {
					Map tm = ymtProductsIWapper
							.selectProductCategoryByCategoryId(rootymtProductsI.getiThirdCategoryId()).get(0);
					Logger.verifyEquals(true, p.getCategoryName().contains(tm.get("sCategory").toString()),
							"验证categoryName");
				}
			} catch (InterruptedException | IOException e) {
				e.printStackTrace();
			}
			List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(p.getProductId());
			for (int i = 0; i < pictures.size(); i++) {
				Logger.verifyEquals(p.getPics().get(i), pictures.get(i).get("sOriUrl").toString(), "验证商品图片地址");
				Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1, "验证商品图片有效");
			}
			p.getCatalogList().forEach(x -> {
				try {
					YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(x.getCatalogId());
					YmtCatalogsI rootCatalog = ymtCatalogsIWapper
							.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
					Logger.verifyEquals(x.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(),
							"验证directPrice");
					if (rootCatalog.getiNum() > 10) {
						Logger.verifyEquals("库存充足", "库存充足", "验证stockInfo");
					} else {
						Logger.verifyEquals("库存紧张", "库存紧张", "验证stockInfo");
					}

					List<Map> maps = ymtCatalogsIWapper.selectCatalogSetAttributesByCatalogId(x.getCatalogId());
					List<String> sCategoryAttribute = maps.stream().map(o -> o.get("sCategoryAttribute").toString())
							.collect(Collectors.toList());
					String s = sCategoryAttribute.get(0);
					for (int i = 1; i < sCategoryAttribute.size(); i++) {
						s = s + " + " + sCategoryAttribute.get(i);
					}
					Logger.verifyEquals(x.getPropertyValue(), s, "验证propertyValue");
					mch_relationWapper mchRelationWapper = new mch_relationWapper();
					int agentType = mchRelationWapper.selectby(
							MapUtil.hashMap("mchId", selectionlistBean.getUserId(), "parentMchId", p.getUserId()))
							.get(0).getAgentType();

					if (x.getAgentPrice() != x.getDirectPrice()) {
						AgentPricePo agentPricePo = ymtProductsIWapper
								.selectAgentPriceByCatalogIdAndAgentType(x.getCatalogId(), agentType).get(0);
						Logger.verifyEquals(x.getAgentPrice(), agentPricePo.getAgentPrice(), "验证agentPrice");
					} else {
						Logger.verifyEquals(x.getAgentPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(),
								"验证agentPrice");
						Logger.verifyEquals(x.getProfit(), 0.0, "验证agentPrice");
					}

				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			});
			mch_infoWapper mchInfoWapper = new mch_infoWapper();
			try {
				mch_info mchInfo = mchInfoWapper.selectby(MapUtil.hashMap("mchId", p.getUserId())).get(0);
				Logger.verifyEquals(mchInfo.getMchTitle(), p.getMchName(), "验证mchName");
				Logger.verifyEquals(mchInfo.getAvatar(), p.getMchPic(), "验证mchPic");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		});
	}

	public static void checkQueryProductList(List<OpenProductDto> openProductDtos,
			QueryProductListBean queryproductlistBean) {
		if (queryproductlistBean.getProductIdList()!=null && queryproductlistBean.getProductIdList().size()>0) {
			openProductDtos.forEach(p -> {
				Logger.verifyEquals(true, queryproductlistBean.getProductIdList().contains(p.getProductId()),
						"验证查询到的商品id是传入的商品id");
			});
		}
		openProductDtos.forEach(p -> {
			try {
				YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(p.getProductId()).get(0);
				AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(p.getProductId());
				AgentProductPo rootProductPo = ymtProductsIWapper
						.selectAgentProductByProductId(agentProductPo.getRootProductId());
				YmtProductsI rootProduct = ymtProductsIWapper
						.selectProductByProductId(agentProductPo.getRootProductId()).get(0);

				Logger.verifyEquals(p.getProductName(), ymtProductsI.getsProduct(), "验证productName");
				Logger.verifyEquals(p.getThirdCategoryId(), rootProduct.getiThirdCategoryId(), "验证thirdCategoryId");
				Logger.verifyEquals(p.getBrandId(), rootProduct.getiBrandId(), "验证brandId");
				Logger.verifyEquals(p.getDeliverType(), rootProduct.getiDeliveryType(), "验证deliverType");
				Logger.verifyEquals(p.getBrandName(), rootProduct.getsBrand(), "验证brandName");
				
				Map map = ymtProductCategoryWapper.getGodProductCategoryByCategoryId(p.getThirdCategoryId()).get(0);
				Logger.verifyEquals(p.getThirdCategoryName(), map.get("sCategory").toString(), "验证sCategory");
				List<Map<String, Object>> pictures = ipm.selectPictureByProdIdAndAction0(p.getProductId());
				for (int i = 0; i < pictures.size(); i++) {
					Logger.verifyEquals(p.getPicList().get(i), pictures.get(i).get("sOriUrl").toString(), "验证商品图片地址");
					Logger.verifyEquals(true, Integer.parseInt(pictures.get(i).get("iAction").toString()) > -1,
							"验证商品图片有效");
				}
				Logger.verifyEquals(p.getProductStatus(), rootProductPo.getStatus(), "验证productStatus");
				Logger.verifyEquals(p.getInfoProgress(), agentProductPo.getInfoProgress(), "验证infoProgress");

				p.getSkuList().forEach(v -> {
					try {
						YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(v.getCatalogId());
						YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper
								.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
						Logger.verifyEquals(v.getOuterSku(), ymtCatalogsI.getsSKU(), "验证sku");
						Logger.verifyEquals(v.getBuyingCurrency(), rootProductPo.getCurrency(), "验证buyingCurrency");
						Logger.verifyEquals(v.getSaleCurrency(), rootProductPo.getCurrency(), "验证saleCurrency");

						Logger.verifyEquals(v.getSalePrice().doubleValue(), ymtCatalogsI.getfQuotePrice().doubleValue(),
								"验证salePrice");

						Logger.verifyEquals(v.getStockNum(), rootYmtCatalogsI.getiNum(), "验证stockNum");
						Logger.verifyEquals(v.getExtraInfo(), null, "验证extraInfo");

						if (agentProductPo.getParentProductId() == null) {
							Logger.verifyEquals(v.getBuyingPrice(), null, "验证BuyPrice");
						} else {
							List<PriceModel> priceModels = ymtProductsIWapper.selectAgentProductPrice(v.getCatalogId());
							Logger.verifyEquals(v.getBuyingPrice().setScale(1).doubleValue(),
									priceModels.get(0).getBuyingPrice(), "验证BuyPrice");
						}

						v.getCatalogPropertyList().forEach(x -> {
							try {
								ipm.selectCatalogProAndValByCatalogId(v.getCatalogId()).forEach(o -> {
									if (x.getPropertyName().equals(o.get("sProductProperty").toString())) {
										Logger.verifyEquals(x.getPropertyValue(),
												o.get("sCategoryAttribute").toString(), "验证propertyValue");
										Logger.verifyEquals(x.getPropertyUrl(), o.get("sPicUrl"), "验证picurl");
									}
								});
							} catch (Exception e) {
								e.printStackTrace();
							}
						});
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

	}
	/**
	 * 修改神器商品的全部规格库存库存
	 * @param sellerid
	 * @param productId
	 * @param catalogId
	 * @param num
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateStock(Integer sellerid,String productId,Integer num) throws InterruptedException, ClientProtocolException, IOException {
		UpdateStockBean updatestockBean=new UpdateStockBean();
		UpdateStockCall updatestockCall=new UpdateStockCall();
		updatestockBean.setUserId(sellerid);
		updatestockBean.setProductId(productId);
		List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(productId);
		List<UpdateStockDto> updateStockDtos = new ArrayList();
		ymtCatalogsIList.forEach(p->{
			UpdateStockDto updateStockDto = new UpdateStockDto();
			updateStockDto.setCatalogId(p.getsCatalogId());
			updateStockDto.setStockNum(p.getiNum());
			updateStockDto.setStockNum(num);
			updateStockDtos.add(updateStockDto);
		});
		updatestockBean.setUpdateStockList(updateStockDtos);
		updatestockCall.setData(updatestockBean);
		updatestockCall.callService();
	}
}
